/**
  CNOK project, Anyang Normal University, IMP-CAS
  \class TAConvolve
  \brief Convolve the theoretical momentum distribution of the A-1 core in a
  single-nucleon knockout reaction to give an experimental value convolved with
  experimental uncertainties. Input: various exp resolutions, and momdis_th
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2022/06/17
  \date Last modified: 2022/06/19 by SUN Yazhou
  \copyright 2020-2023 SUN Yazhou
  \copyright CNOK project, Anyang Normal University, IMP-CAS
*/

#ifndef _TAConvolve_h_
#define _TAConvolve_h_

#include <string>
#include <vector>
#include <fstream>

using std::vector;
using std::string;
using std::ofstream;

class TAConvolve{
public:
  /// \param ap,zp,zc: identity of the projectile and the core
  /// \param ek: projectile incident energy per u (in MeV/u) in lab frame
  /// \param expres: experiment resolution
  TAConvolve(int ap, int zp, int zc, double ek, const string &expres);
  virtual ~TAConvolve(){}

  /// \retval exp momdis \param pvz: momentum of valence nucleon in proj. c.m. frame
  double ExpMom(double pvz) const;

  /// generate random number with pdf as f(x) with length l
  /// using hit or miss method
  static double HitOrMiss(int l, const double *x, const double *f);
  /// \param cc: normalization constant
  void ExpMomDis(int l, const double *x, const double *f, double cc,
    vector<double> &xconv, vector<double> &fconv, ofstream &fout) const;

protected:
  int fAp, fZp, fZc;
  double fMp, fMc; ///< mass of the projectile and the (A-1) core in MeV
  double fEk; ///< projectile incident energy per u (in MeV/u) in lab frame
  double fPp, fdPp; ///< projectile momentum and its uncertainty
  double fBG0; ///< the beta*gamma of the projectile
  double fPc0; ///< core momentum in lab frame without pc_c.m.

  //////------ The experimental resolutions -------//////
  // terminology: bg, or BG: beta*gamma
  // terminology: ETF: the External Target Facility in HIRFL-CSR, IMP (in Lanzhou, China)
  // terminology: RIBLL2: the 2nd Radioactive Ion Beam Line in Lanzhou
  // momentum resolution for the PID of the mass (A-1) fragment (frag) represented by
  // sigma(beta*gamma) (poz=aoz*beta*gamma, aoz is constant after PID of the frag)
  double DBG; // 2.00767e-3: typical value for ETF

  // relative angular resolution for the fragment: sigma(cospl)/cospl, where pl is
  // the angule <n0, n1>, with n0 and n1 the unit vectors of the directions of the
  // the incident projectile and the outgoing frag
  double DCOSREL; // 6.e-7: typical value for ETF

  // sigma(beta*gamma) of the radioactive ion beamline, namely its bg resolution
  // usually can be extracted, e.g., from primary beams which have negligibly narrow
  // momentum straggling
  double DBG0; // 8.06986e-4: typical value for RIBLL2

  // measuremed sigma(beta*gamma) of the incident secondary beam
  // = rms(DBG0, intrinsic sigma(bg) of the incident secondary beam)
  double SDBG0; // 1.86228e-03: typical value for RIBLL2

  // intrinsic sigma(beta*gamma) resulting from production of the secondary beam
  // in the primary target via projectile fragmentation
  double PDBG0; // = sqrt(SDBG0*SDBG0 - DBG0*DBG0);
};

#endif
